import { wechatrequest } from './API/request'

/**
 * 小程序获取openid
 */
export const wxLoginRequest = ({ code }) => {
  return wechatrequest.postparams(
    `@@/auth/token`,
    {
      data: {
        code,
        grant_type: 'wx_openid'
      }
    },
    true
  )
}

/**
 * 刷新token
 */
export const refreshTokenRequest = ({ refreshToken }) => {
  return wechatrequest.postparams(
    `@@/auth/token`,
    {
      data: {
        grant_type: 'refresh_token',
        refresh_token: refreshToken
      }
    },
    true
  )
}

/**
 * 登录
 */
export const loginRequest = ({ mobile, code, type, identifier }) => {
  return wechatrequest.post(`@@/auth/mobile/change`, {
    data: { mobile, code, type, identifier }
  })
}

/**
 * 手机号登录解密数据
 */
export const extractPhoneRequest = ({ openId, encryptedData, iv }) => {
  return wechatrequest.post(`@@/weixin/eptdata/extract`, {
    data: { openId, encryptedData, iv }
  })
}

/**
 * 手机号一键登录
 */
export const bindPhoneRequest = ({ openId, mobile }) => {
  return wechatrequest.post(`@@/auth/mobile/bind`, {
    data: {
      identifier: openId,
      type: 'openId',
      mobile,
      code: ''
    }
  })
}